package ar.edu.unq.mongodbexample.homes;

import java.util.List; 

import ar.edu.unq.mongodbexample.model.Professor;
import ar.edu.unq.mongodbexample.persistence.MongoDBManager;

import com.google.code.morphia.dao.BasicDAO;

public class ProfessorHome extends BasicDAO<Professor, Integer> implements IHome<Professor> {
    public ProfessorHome() {
        super(Professor.class, MongoDBManager.getInstance().getDataStore());
        MongoDBManager.getInstance().getMorphia().map(Professor.class);

    }

	public int saveAll(List<Professor> entityList) {
		int notSaved=0;
    	for(Professor professor:entityList){
    		try{
    			this.save(professor);
    		}
    		catch (Exception e) {
				notSaved=notSaved+1;
			}
    	}
    	return notSaved;
	}

	public List<Professor> getAll() {
		 return ds.find(Professor.class).asList();
	}

	public Professor findById(Object id) {
		return (Professor) ds.get(Professor.class,id);
	}
}
